﻿using System;
using System.Collections;
using System.Xml;
using InfoJetSoft.Service.Entity;
using InfoJetSoft.Service.Util;

namespace InfoJetSoft.Service.Worker
{
	
	class XmlXmlToEditParentWorker
	{
		
		public static void  parseParent(XmlToEditContext context)
		{
			XmlToEdit xmlToEdit = context.XmlToEdit;
			XmlElement root = context.Doc.DocumentElement;
			ArrayList contextIdList = context.ContextIdList;
			ArrayList chooseFragmentList = xmlToEdit.ChooseFragmentList;
			ChooseFragment existChooseFragment = null;
			XmlNode parentNode = null;
			foreach (ChooseFragment chooseFragment in chooseFragmentList)
			{
				string parent = chooseFragment.Parent;
				XmlNodeList parentXmlNodeList = DOMUtil.selectNodes(context.ContainerNode, chooseFragment.Parent, 0, context.NsResolver);
				if (parentXmlNodeList.Count > 0)
				{
					existChooseFragment = chooseFragment;
					parentNode = parentXmlNodeList[ 0 ];
					break;
				}
			}
			if (existChooseFragment == null || parentNode == null)
			{
				throw new InfoJetException("not found parent", "XXEP01");
			}
			context.ExistChooseFragment = existChooseFragment;
			context.ParentNode = parentNode;
		}
	}
}